import 'package:flutter/material.dart';
import 'package:flutter_application_1/global.dart';
import './native_refresh.dart';
import './native_refresh_ios.dart';
import './plugin_refresh.dart';
import './plugin_refresh_water_drop.dart';
import './plugin_refresh_classic_header.dart';
import './plugin_refresh_bg_mask.dart';
import './lottie_refresh.dart';

class RefreshPage extends StatefulWidget {
  @override
  _RefreshPageState createState() => _RefreshPageState();
}

class TabData {
  String name;
  Widget view;

  TabData({
    required this.name,
    required this.view,
  });
}

class _RefreshPageState extends State<RefreshPage> {
  List<TabData> _tabList = [];

  @override
  void initState() {
    super.initState();
    _tabList = [
      TabData(
        name: '原生下拉刷新',
        view: NativeRefresh(),
      ),
      TabData(
        name: 'ios下拉刷新',
        view: NativeRefreshIos(),
      ),
      TabData(
        name: '插件下拉刷新',
        view: PluginRefresh(),
      ),
      TabData(
        name: '水滴下拉刷新',
        view: PluginRefreshWaterDrop(),
      ),
      TabData(
        name: '插件ClassicHeader',
        view: PluginRefreshClassicHeader(),
      ),
      TabData(
        name: '插件图片遮挡',
        view: PluginRefreshBgMask(),
      ),
      TabData(
        name: '缩放的SliverAppBar',
        view: Center(
          child: ElevatedButton(
            child: Text('跳转'),
            onPressed: () {
              Global.routerUtils.navigateTo(
                context,
                Global.routeMap.customListPage,
              );
            },
          ),
        ),
      ),
      TabData(
        name: 'lottie 刷新',
        view: LottieRefresh(),
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: _tabList.length,
      child: Scaffold(
        appBar: AppBar(
          title: Text('下拉刷新测试'),
          centerTitle: true,
          bottom: TabBar(
            isScrollable: true,
            indicatorPadding: EdgeInsets.symmetric(vertical: 5, horizontal: 3),
            tabs: _tabList.map((e) => Tab(text: e.name)).toList(),
          ),
        ),
        body: TabBarView(
          children: _tabList.map((e) => e.view).toList(),
        ),
      ),
    );
  }
}
